package com.bgds.sys.module.controller;

import cn.hutool.core.util.ObjectUtil;
import com.bgds.sys.common.constant.BizConstant;
import com.bgds.sys.common.pagevo.Result;
import com.bgds.sys.common.utils.ResultUtil;
import com.bgds.sys.influx.service.InfluxService;
import com.bgds.sys.module.entity.AlarmLog;
import com.bgds.sys.module.entity.DeviceDynamicAttr;
import com.bgds.sys.module.service.IDeviceDynamicAttrService;
import com.bgds.sys.task.AlarmJob;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

/**
 * @author lj
 */
@Slf4j
@RestController
@Api(tags = "报警设置管理接口")
@RequestMapping("/alarmLimit")
public class AlarmLimitController {
    @Autowired
    private InfluxService influxService;
    @Autowired
    private IDeviceDynamicAttrService iDeviceDynamicAttrService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ApiOperation(value = "保存报警设置",notes = "保存报警设置",httpMethod = "POST")
    public Result<Object> addOrUpdate(@RequestBody DeviceDynamicAttr attr){
        Boolean b = iDeviceDynamicAttrService.addOrUpdate(attr);
        if (!b){
            return new ResultUtil<Object>().setSuccessMsg("失败");
        }
        return new ResultUtil<Object>().setSuccessMsg("修改成功");
    }



    /**
     * 设备编码获取设备数据项
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "设备编码获取设备数据项",notes = "设备编码获取设备数据项",httpMethod = "GET",response = Result.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deviceCode", dataType = "String", required = true, value = "设备编号"),
            @ApiImplicitParam(name = "judgeType", dataType = "Integer", required = true, value = "判断的类型")
    })
    public Result<List<DeviceDynamicAttr>> getDeviceDynamic(String deviceCode,@RequestParam(required = false)  Integer judgeType){
        List<DeviceDynamicAttr> deviceDynamicAttrList=iDeviceDynamicAttrService.listByDeviceCodeAndJudgeType(deviceCode,judgeType)
                .stream()
                .filter(d -> !d.getName().contains("给定"))
                .filter(d -> !d.getName().contains("额定"))
                .filter(d -> !d.getName().contains("设定"))
                .collect(Collectors.toList());

        return new ResultUtil<List<DeviceDynamicAttr>>().setData(deviceDynamicAttrList);
    }




}
